package top.i51213.fastaction;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentContainerView;

import android.Manifest;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.widget.Toast;

import com.permissionx.guolindev.PermissionX;

import top.i51213.fastaction.view.BrowserActivity;
import top.i51213.fastaction.view.OfficeReaderActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
            PermissionX.init(this)
                    .permissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                    .onExplainRequestReason(
                            (scope, deniedList) ->
                                    scope.showRequestReasonDialog(deniedList, "应用基于这些权限实现", "确定", "取消"))
                    .request(
                            (allGranted, grantedList, deniedList) -> {
                                if (allGranted) {
                                    // Toast.makeText(this, "已授权所有必须权限", Toast.LENGTH_LONG).show();
                                } else {
                                    Toast.makeText(this, "部分权限尚未授权,应用可能无法正常运行", Toast.LENGTH_LONG).show();
                                }
                            });
        }
        if(BuildConfig.DEBUG){
            new AlertDialog.Builder(this).setNegativeButton("browser", (dialog, which) -> {
                System.out.println("start new activity");
                startActivity(new Intent(MainActivity.this, BrowserActivity.class));
                finish();
            }).setPositiveButton("OfficeReader", (dialog, which) -> {
                System.out.println("start new activity");
                startActivity(new Intent(MainActivity.this, OfficeReaderActivity.class));
                finish();
            }).show();

        }
    }
}